<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">


    <title>H+ 后台主题UI框架 - 登录</title>
    <!--<link rel="shortcut icon" href="favicon.ico">-->
    <link href="css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="css/animate.css" rel="stylesheet">
    <link href="css/style.css?v=4.1.0" rel="stylesheet">
    <!--[if lt IE 9]>
    <meta http-equiv="refresh" content="0;ie.html" />
    <![endif]-->
    <script>if(window.top !== window.self){ window.top.location = window.location;}</script>
</head>

<body class="gray-bg">
    <div class="middle-box text-center loginscreen  animated fadeInDown">
        <div>
            <div>
                <h1 class="logo-name">H+</h1>
            </div>
            <h3>登录：</h3>
            <form id="signupForm">
                <input type="text" name="username" class="form-control uname"
                       placeholder="用户名" />
                <input type="password" name="password"
                       class="form-control pword m-b" placeholder="密码" />
                <button class="btn btn-success btn-block">登录</button>
            </form>
        </div>
    </div>
    <!-- 全局js -->
    <script src="js/jquery.min.js?v=2.1.4"></script>
    <script src="js/bootstrap.min.js?v=3.3.6"></script>
    <!-- 自定义js -->
    <script src="js/content.js?v=1.0.0"></script>
    <!-- Validate-->
    <script src="js/plugins/validate/jquery.validate.min.js"></script>
    <script src="js/plugins/validate/messages_zh.min.js"></script>
    <script src="js/plugins/layer/layer.min.js"></script>

    <script type="text/javascript">
        $(document).ready(function() {
            validateRule();
        });

        $.validator.setDefaults({
            submitHandler : function() {
                login();
            }
        });

        function login() {
            $.ajax({
                type : "POST",
                url : "/login",
                data : $('#signupForm').serialize(),
                success : function(r) {
                    if (r.code == 0) {
                        parent.location.href = '/index';
                    } else {
                        layer.msg(r.msg);
                    }
                }
            });
        }

        function validateRule() {
            var icon = "<i class='fa fa-times-circle'></i> ";
            $("#signupForm").validate({
                rules : {
                    username : {
                        required : true
                    },
                    password : {
                        required : true
                    }
                },
                messages : {
                    username : {
                        required : icon + "请输入您的用户名"
                    },
                    password : {
                        required : icon + "请输入您的密码"
                    }
                }
            })
        }
    </script>

</body>

</html>
